# _*_ coding: utf-8 _*_
from openerp import models, fields, api



class ProductTemplate(models.Model):
    _inherit = "product.template"

    name = fields.Char('Name', index=True, required=False, translate=True)
    product_parameter_ids = fields.One2many("product.parameter", "product_id",
                                            string="Product Parameter")
    product_url = fields.Char(string="Product URL", compute="_compute_product_url")
    # _sql_constraints = [
    #     ('default_code_uniq',
    #      'UNIQUE (name,default_code)',
    #      '产品件号+名称必须唯一！')
    # ] 取消了，因为在复制产品时会提示改错误

    @api.depends("product_parameter_ids",
                 "product_parameter_ids.url")
    def _compute_product_url(self):
        for product in self:
            if product.product_parameter_ids:
                product.product_url = product.product_parameter_ids[0].url
